-- USER
-- Object:  Table [HAB_SGBD_USER]    Script Date: 12/23/2012 16:27:54
CREATE TABLE HAB_SGBD_USER 
(
  USER_ID NUMBER NOT NULL
, USER_LOGIN VARCHAR2(255) NOT NULL
, USER_PASSWORD VARCHAR2(255) NOT NULL
, USER_FNM VARCHAR2(255) NOT NULL
, USER_LNM VARCHAR2(255) NOT NULL 
, USER_CREATED DATE NOT NULL
, USER_LAST_LOG DATE NULL
, USER_STATUS NUMBER NOT NULL
, USER_ADMIN NUMBER NOT NULL
, CONSTRAINT PK_USER_ID PRIMARY KEY
  (
    USER_ID 
  )
  ENABLE 
);
CREATE SEQUENCE hab_sgbd_user_seq;

-- Object:  Sequence [USER_ID] AUTO INCREMENT     Script Date: 12/23/2012 16:27:54
CREATE OR REPLACE TRIGGER hab_sgbd_user_autoIncrement 
BEFORE INSERT ON HAB_SGBD_USER
FOR EACH ROW

BEGIN
  SELECT hab_sgbd_user_seq.NEXTVAL
  INTO   :new.USER_ID
  FROM   dual;
END;
/

-- Object:  Table [RFA_SGBD_RULE]    Script Date: 12/25/2012 11:26:31
CREATE TABLE RFA_SGBD_RULE
(
  RULE_ID NUMBER NOT NULL
, RULE_NM VARCHAR2(255) NOT NULL
, CONSTRAINT PK_RULE_ID PRIMARY KEY
  (
    RULE_ID 
  )
  ENABLE 
);
CREATE SEQUENCE rfa_sgbd_rule_seq;

-- Object:  Sequence [RULE_ID] AUTO INCREMENT     Script Date: 12/25/2012 11:26:31
CREATE OR REPLACE TRIGGER rfa_sgbd_rule_autoIncrement 
BEFORE INSERT ON RFA_SGBD_RULE
FOR EACH ROW

BEGIN
  SELECT rfa_sgbd_rule_seq.NEXTVAL
  INTO   :new.RULE_ID
  FROM   dual;
END;
/

-- Object:  Table [RFA_SGBD_TYPE_DATABASE]    Script Date: 12/29/2012 18:24:31
CREATE TABLE RFA_SGBD_TYPE_DATABASE
(
  TDT_ID NUMBER NOT NULL
, TDT_NM VARCHAR2(255) NOT NULL
, CONSTRAINT PK_TDT_ID PRIMARY KEY
  (
    TDT_ID 
  )
  ENABLE 
);
CREATE SEQUENCE rfa_sgbd_tdt_seq;

-- Object:  Sequence [TDT_ID] AUTO INCREMENT     Script Date: 12/29/2012 18:24:31
CREATE OR REPLACE TRIGGER rfa_sgbd_tdt_autoIncrement 
BEFORE INSERT ON RFA_SGBD_TYPE_DATABASE
FOR EACH ROW

BEGIN
  SELECT rfa_sgbd_tdt_seq.NEXTVAL
  INTO   :new.TDT_ID
  FROM   dual;
END;
/

-- Object:  Table [RFU_SGBD_DATABASE]    Script Date: 12/25/2012 11:26:31
CREATE TABLE RFU_SGBD_DATABASE
(
  DB_ID NUMBER NOT NULL
, DB_NNM VARCHAR2(255) NOT NULL
, DB_HOST VARCHAR2(255) NOT NULL
, DB_PORT NUMBER NOT NULL
, DB_NM VARCHAR2(255) NOT NULL
, DB_CREATED DATE NOT NULL
, DB_TDT_ID NUMBER NOT NULL
, DB_USER_ID NUMBER NOT NULL
, DB_RULE_ID NUMBER NOT NULL
, CONSTRAINT PK_DB_ID PRIMARY KEY
  (
    DB_ID 
  )
  ENABLE 
);
CREATE SEQUENCE rfu_sgbd_database_seq;

-- Object:  ForeignKey [FK_DB_TDT_ID]	Script Date: 12/29/2012 18:24:31
ALTER TABLE RFU_SGBD_DATABASE
add CONSTRAINT FK_DB_TDT_ID
  FOREIGN KEY (DB_TDT_ID)
  REFERENCES RFA_SGBD_TYPE_DATABASE(TDT_ID);

-- Object:  ForeignKey [FK_DB_USER_ID]	Script Date: 12/25/2012 11:26:31
ALTER TABLE RFU_SGBD_DATABASE
add CONSTRAINT FK_DB_USER_ID
  FOREIGN KEY (DB_USER_ID)
  REFERENCES HAB_SGBD_USER(USER_ID);

-- Object:  ForeignKey [FK_DB_RULE_ID]	Script Date: 12/25/2012 11:26:31
ALTER TABLE RFU_SGBD_DATABASE
add CONSTRAINT FK_DB_RULE_ID
  FOREIGN KEY (DB_RULE_ID)
  REFERENCES RFA_SGBD_RULE(RULE_ID);

-- Object:  Sequence [DB_ID] AUTO INCREMENT     Script Date: 12/25/2012 11:26:31
CREATE OR REPLACE TRIGGER rfu_sgbd_db_seq_autoIncrement 
BEFORE INSERT ON RFU_SGBD_DATABASE
FOR EACH ROW

BEGIN
  SELECT rfu_sgbd_database_seq.NEXTVAL
  INTO   :new.DB_ID
  FROM   dual;
END;
/

-- Object:  Table [RFA_INT_PAGE]    Script Date: 03/01/2013 11:50:42
CREATE TABLE RFA_INT_PAGE
(
  PG_ID NUMBER NOT NULL
, PG_NM VARCHAR2(255) NOT NULL
, CONSTRAINT PK_PG_ID PRIMARY KEY
  (
    PG_ID 
  )
  ENABLE 
);
CREATE SEQUENCE rfa_int_page_seq;

-- Object:  Sequence [PG_ID] AUTO INCREMENT     Script Date: 03/01/2013 11:50:42
CREATE OR REPLACE TRIGGER rfa_int_page_autoIncrement 
BEFORE INSERT ON RFA_INT_PAGE
FOR EACH ROW

BEGIN
  SELECT rfa_int_page_seq.NEXTVAL
  INTO   :new.PG_ID
  FROM   dual;
END;
/

-- Object:  Table [RFA_INT_TAB]    Script Date: 03/01/2013 11:50:42
CREATE TABLE RFA_INT_TAB
(
  TAB_ID NUMBER NOT NULL
,TAB_NM VARCHAR2(255) NOT NULL
,TAB_ICON VARCHAR2(50) NOT NULL
,TAB_ADMIN NUMBER NOT NULL
, TAB_PAGE_ID NUMBER NOT NULL
, CONSTRAINT PK_TAB_ID PRIMARY KEY
  (
    TAB_ID 
  )
  ENABLE 
);
CREATE SEQUENCE rfa_int_tab_seq;

-- Object:  Sequence [TDT_ID] AUTO INCREMENT     Script Date: 03/01/2013 11:50:42
CREATE OR REPLACE TRIGGER rfa_int_tab_autoIncrement 
BEFORE INSERT ON RFA_INT_TAB
FOR EACH ROW

BEGIN
  SELECT rfa_int_tab_seq.NEXTVAL
  INTO   :new.TAB_ID
  FROM   dual;
END;
/

-- Object:  ForeignKey [FK_TAB_PAGE_ID]	Script Date: 03/01/2013 11:50:42
ALTER TABLE RFA_INT_TAB
add CONSTRAINT FK_TAB_PAGE_ID
  FOREIGN KEY (TAB_PAGE_ID)
  REFERENCES RFA_INT_PAGE(PG_ID);
/

-- Object:  Table [APP_INT_LOG]    Script Date: 14/01/2013 13:16:45
CREATE TABLE APP_INT_LOG
(
  LOG_ID NUMBER NOT NULL
,LOG_DATE DATE NOT NULL
,LOG_IP VARCHAR2(20) NOT NULL
,LOG_MSG VARCHAR(255) NOT NULL
,LOG_USER_ID NUMBER NOT NULL
, CONSTRAINT PK_LOG_ID PRIMARY KEY
  (
    LOG_ID 
  )
  ENABLE 
);
CREATE SEQUENCE app_int_log_seq;

-- Object:  Sequence [TDT_ID] AUTO INCREMENT     Script Date: 14/01/2013 13:16:45
CREATE OR REPLACE TRIGGER app_int_log_autoIncrement 
BEFORE INSERT ON APP_INT_LOG
FOR EACH ROW

BEGIN
  SELECT app_int_log_seq.NEXTVAL
  INTO   :new.LOG_ID
  FROM   dual;
END;
/

-- Object:  ForeignKey [FK_LOG_USER_ID]	Script Date: 14/01/2013 13:16:45
ALTER TABLE APP_INT_LOG
add CONSTRAINT FK_LOG_USER_ID
  FOREIGN KEY (LOG_USER_ID)
  REFERENCES HAB_SGBD_USER(USER_ID);
/